<?php
namespace app\home\model;

use \think\Model as Model;
class Paper extends Model{
    protected $pk = 'pap_id';

    public function getchoice(){
        // $comm = "select p.*,c.*,count(pap_name) from de_paper p left join de_choice as c on p.pap_id = c.pap_id group by pap_name;";
        $str_sql = "select p.*,count(*) as total from edu_paper p left join edu_paper_choice as c on p.pap_id = c.pap_id where p.pap_type = '1' group by pap_name;";
        // $str_sql = "select p.*,c.*,e.*,count(*) as total from edu_paper p left join edu_paper_choice as c on p.pap_id = c.pap_id left join edu_paper_essay as e on p.pap_id = e.pap_id group by p.pap_id;";
        // $str_sql = "select p.*,e.*,count(*) as total from edu_paper p left join edu_paper_essay as e on p.pap_id = e.pap_id group by p.pap_id;";

        // $data = $this->alias('p')->field('p.*')->join('choice c','c.pap_id=p.pap_id')->select();
        $data = $this->query($str_sql);
        return $data;
        // var_dump($data);
        
    }

    public function getessay(){
        $str_sql = "select p.*,count(*) as total from edu_paper p left join edu_paper_essay as e on p.pap_id = e.pap_id where p.pap_type = '2' group by p.pap_id;";
        $data = $this->query($str_sql);
        return $data;
    }
}
